<template>
  <right-cont ref="dom">
    <template #header>
      <div class="">
        <Back></Back>
        id:{{id}}
      </div>
    </template>
    <template #cont>
      <div>DemoInfo</div>
      <div class="gsapred" ref="com"></div>
        <el-form
          ref="ruleFormRef"
          :model="ruleForm"
          label-width="120px"
          class="demo-ruleForm"
          :size="formSize"
          status-icon
        >
          <el-form-item label="Activity name" prop="name">
            <el-input v-model="ruleForm.name" />
          </el-form-item>
          <el-form-item label="Activity zone" prop="region">
            <el-select v-model="ruleForm.region" placeholder="Activity zone">
              <el-option label="Zone one" value="shanghai" />
              <el-option label="Zone two" value="beijing" />
            </el-select>
          </el-form-item>
          <el-form-item label="Activity count" prop="count">
            <el-select-v2
              v-model="ruleForm.count"
              placeholder="Activity count"
              :options="options"
            />
          </el-form-item>
          <el-form-item label="Activity time" required>
            <el-col :span="11">
              <el-form-item prop="date1">
                <el-date-picker
                  v-model="ruleForm.date1"
                  type="date"
                  label="Pick a date"
                  placeholder="Pick a date"
                  style="width: 100%"
                />
              </el-form-item>
            </el-col>
            <el-col class="text-center" :span="2">
              <span class="text-gray-500">-</span>
            </el-col>
            <el-col :span="11">
              <el-form-item prop="date2">
                <el-time-picker
                  v-model="ruleForm.date2"
                  label="Pick a time"
                  placeholder="Pick a time"
                  style="width: 100%"
                />
              </el-form-item>
            </el-col>
          </el-form-item>
          <el-form-item label="Instant delivery" prop="delivery">
            <el-switch v-model="ruleForm.delivery" />
          </el-form-item>
          <el-form-item label="Activity type" prop="type">
            <el-checkbox-group v-model="ruleForm.type">
              <el-checkbox label="Online activities" name="type" />
              <el-checkbox label="Promotion activities" name="type" />
              <el-checkbox label="Offline activities" name="type" />
              <el-checkbox label="Simple brand exposure" name="type" />
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="Resources" prop="resource">
            <el-radio-group v-model="ruleForm.resource">
              <el-radio label="Sponsorship" />
              <el-radio label="Venue" />
            </el-radio-group>
          </el-form-item>
          <el-form-item label="Activity form" prop="desc">
            <el-input v-model="ruleForm.desc" type="textarea" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm(ruleFormRef)">
              Create
            </el-button>
            <el-button @click="resetForm(ruleFormRef)">Reset</el-button>
          </el-form-item>
        </el-form>
    </template>
  </right-cont>
</template>

<script setup lang="ts">
import RightCont from "@/components/Content/rightCont.vue";

const props = defineProps(['id'])

import {gsap} from "gsap";
import {onMounted, reactive, ref } from "vue";



import type { FormInstance } from 'element-plus'
interface RuleForm {
  name: string
  region: string
  count: string
  date1: string
  date2: string
  delivery: boolean
  type: string[]
  resource: string
  desc: string
}

const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()
const ruleForm = ref<RuleForm>({
  name: '111',
  region: '',
  count: '',
  date1: '',
  date2: '',
  delivery: false,
  type: [],
  resource: '',
  desc: '',
})


const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
    } else {
      console.log('error submit!', fields)
    }
  })
}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}

const options = Array.from({ length: 10000 }).map((_, idx) => ({
  value: `${idx + 1}`,
  label: `${idx + 1}`,
}))







let com = ref(null)
let tween_start = null
let tween_end = null
function start(){
  gsap.fromTo(com.value, { opacity: 0 ,x: 350},{ duration: 1, x:0, opacity:1 })
  // tween_start.play()
}
// 关闭动画
function close(){
  gsap.fromTo(com.value, { x: 600 },{ duration: 0.75, opacity:0 })
  tween_end.play()
}
let init = () => {
  console.log('com.value',com.value)
  // gsap.to(com.value,{transform:'translateX(-30px)',opacity:1,duration:2, delay: 0,onComplete:()=>{}})

  // tween_start = gsap.from(com.value, { duration: 1, delay: 0, x: 350,paused: true })
  tween_end = gsap.fromTo(com.value, { x: 0 }, { duration: 0.75, delay: 0, x: 350 ,paused: true ,onComplete: ()=>{
    close()
  }})

}
onMounted(()=>{
  gsap.fromTo(com.value, { opacity: 0 ,x: 350},{ duration: 1, x:0, opacity:1 })
})
let dom = ref(null)
defineExpose({
  dom:dom
})
</script>

<style scoped lang="scss">
.header {
  margin-bottom: 22px;
  text-align: right;
}
.gsapred{
  width: 100px;
  height: 100px;
  background: #97a8be;
}
</style>
